﻿
function inituvote() {
    $('.uvote').each(function () {
        $(this).html('');
    });
    $('.uvote').each(function () {
        var star = $(this).attr("star");
        var id = $(this).attr("id");
        var re = $(this).attr("enable") == 'true' ? true : false;
        var ha = $(this).attr("half") == 'false' ? false : true;
        var ca = $(this).attr("cancel") == 'true' ? true : false;
        $('#' + id).raty({
            readOnly: !re, half: ha, start: star,
            hintList: [lang_vote1, lang_vote2, lang_vote3, lang_vote4, lang_vote5],
            cancel: true, cancelHint: lang_voteCancelHint,
            click: function (score, evt) {
                if (score == null)
                    score = 0;
                $(this).attr("star", score);
            }
        });
    });
}
function textCounter(textarea, countdown, maxlimit) {
    textareaid = document.getElementById(textarea);
    if (textareaid.value.length > maxlimit)
        textareaid.value = textareaid.value.substring(0, maxlimit);
    else
        document.getElementById(countdown).value = '-' + (maxlimit - textareaid.value.length) + '-';
}
function getComment(data) {
    var c = data;
    if (c != null) {

        for (var i = 0; i < c.length; i++) {
            var item = "<div class='citem'><div class='cinfo'><a>" + c[i].UserName + "</a><br />(" + c[i].ModifiedDate + ")<br /><div id='uvote" + c[i].CommentID + "' class='uvote' star='" + c[i].Vote + "'></div></div>" + c[i].Comment + "</div>";
            $('#commentlist').append(item);
        }
        inituvote();
    }
    if (c == null) {
        alert('getComment null');
    }
}


$(document).ready(function () {
    createSlideShow(2, '#slider', '');
    

    inituvote();

    $('#sharelinktoyahoo').attr('href', 'ymsgr:im?+&msg=' + window.location + ' <== ' + $(this).attr('title'));
    $('#sharetofacebook').attr('href', 'http://www.facebook.com/sharer.php?u=' + window.location + '&t=' + $(this).attr('title'));
    
    

    if ($("#SameProductslist").html() == "")
        getjson("services/WebService.asmx/GetProductsByCategoryID", '#SameProductslist',
         '{CategoryID:' + cCategoryID + ', Lang: "' + lang + '", Take:' + 8 + ', Skip:' + 0 + ' ,FromPrice:0, ToPrice:100000000}');


    if (cProductQuantity < 1) {
        $('#shoppingFunction').html(lang_OutOfStock);
    }
    else {
        $('#txtSoLuong').attr('maxlength', cProductQuantity);
    }
    //addtocart click
    $('#btnProductdetailAddToCart').click(function () {
        var userchoicequantity = parseInt($('#txtSoLuong').val());
        if (isNaN(userchoicequantity))
            userchoicequantity = 1;
        $.get('usercontrols/AddToCart.aspx?pid=' + cProductID + '&q=' + userchoicequantity, function (data) {
            if (data > 0) {
                $('#iconcartItemcount').html(data);
                $('#cartItemcount').html(data);
            }
            else {
                alert(data);
            }
        });
    });
    getjsonList("services/WebService.asmx/GetProductComment",
                                     '{pProductID:' + cProductID + '}',
                                     "getComment");

    $('btnLoadMoreComment').click(function () { });
    

    $('.jqzoom').jqzoom({
        zoomType: 'standard',
        lens: true,
        preloadImages: true,
        alwaysOn: false,
        zoomWidth: 363,
        zoomHeight: 327,
        title: false
    });
    $("div#makeMeScrollable").smoothDivScroll({});

});
